<template>
  <div class="user" @click.self="addusershow">
    <el-form status-icon label-width="100px" class="demo-ruleForm" :rules="rules" :model="obj">
      <h4 style="margin-bottom:20px">修改信息</h4>
      <el-form-item label="用户名" prop="username">
        <el-input type="username" autocomplete="off" disabled v-model="obj.username"></el-input>
      </el-form-item>
      <el-form-item prop="email" label="邮箱">
        <el-input v-model="obj.email"></el-input>
      </el-form-item>
      <el-form-item prop="mobile" label="手机号">
        <el-input v-model="obj.mobile"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm('obj')">确定</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { http } from "../network/index";
export default {
  props: ["obj"],
  data() {
    return {
      rules: {
        email: [
          { required: true, message: "请输入邮箱地址", trigger: "blur" },
          {
            type: "email",
            message: "请输入正确的邮箱地址",
            trigger: ["blur", "change"],
          },
        ],
        mobile: [{ required: true, message: "请输入手机号", trigger: "blur" }],
      },
    };
  },
  methods: {
    addusershow() {
      this.$emit("adduserclick");
    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          http
            .xiugaiusers({
              id: this.obj.id,
              email: this.obj.email,
              mobile: this.obj.mobile,
            })
            .then((res) => {
              this.$message({
                message: res.data.meta.msg,
                type: "success",
              });
              window.location.reload();
            });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
  },
  mounted() {
    // console.log(this.obj);
  },
};
</script>

<style lang="scss" scoped>
.user {
  width: 100%;
  height: 100vh;
  position: fixed;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, 0.2);
  display: flex;
  justify-content: center;
  align-items: center;
  .el-form {
    width: 30%;
    background: #fff;
    padding: 20px;
    // margin-left: -200px;
    border-radius: 20px;
    /deep/ .el-input,
    input {
      width: 75%;
    }
  }
}
</style>